package com.gw.vip.center.jwt;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import com.gw.vip.center.constant.VipCenterKey;

/**
 * @author GW
 * @description
 * @since 2022-03-31
 */
public class JwtUtil {

    private static final byte[] key = "goeggew".getBytes();

    public static String token(TokenInfo tokenInfo){
        return JWT.create()
                .setPayload(VipCenterKey.USER_ID, tokenInfo.getUserId())
                .setKey(key)
                .sign();
    }

    public static TokenInfo parse(String token){
        final JWT jwt = JWTUtil.parseToken(token);
        TokenInfo tokenInfo = new TokenInfo();
        tokenInfo.setUserId((String) jwt.getPayload(VipCenterKey.USER_ID));
        return tokenInfo;
    }

    public static boolean verify(String token){
        return JWTUtil.verify(token, key);
    }
}
